function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}


/**
*honour方法通过判断账户价值和游戏排名的大小来决定返回的称谓,返回名次较好的
*@param acountRanking 为游戏账户价值排名
*@param gameRanking 为某款游戏的数组,[0]为游戏id，[1]为游戏排名
*return string 称谓字符串
*/

function honour(acountRanking,gameRanking){
  let gameIdArr = [578080,433850,271590,322330,730,105600,402130,570,381210,359550],
      gameNameArr = ["吃鸡","跳伞","GTA5","饥荒","CSgo","Terraria","辐射4","刀塔2","黎明杀机","彩虹6号"],
      returnHonour = "";

     if(acountRanking < gameRanking[1]){
        return  "第"+convert(acountRanking)+"神豪"
     }else{
        return  "第"+convert(gameRanking[1])+ gameNameArr[gameIdArr.indexOf(gameRanking[0])]
     }

     function convert(num){
      const numArr = ['十','一','二','三','四','五','六','七','八','九'];

      if(num <10 && num !=0){
        return numArr[num];
      }else if(num == 10){
        return numArr[0];
      }
      
      let numStrArr = num.toString().split("");
      if(numStrArr.length == 2){
        if(numStrArr[1]=="0"){
          return ""+numArr[parseInt(numStrArr[0])]+ numArr[parseInt(numStrArr[1])]
        }
        return numArr[numStrArr[0]] + "十" + numArr[numStrArr[1]]
      }
     }
}


/*

const sortArr = ['十','一','二','三','四','五','六','七','八','九'];
// fh=>fHonour,sh=>sHonour
function showHonour(fh,sh){
  let reg = /^\u7B2C[\u5341|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94\u516D|\u4E03\u516B|\u4E5D]{1,3}/;
  let fArr = reg.exec(fh)[0].substr(1).split('');
  let sArr = reg.exec(sh)[0].substr(1).split('');
  let fNum='',sNum='';
  fNum = convert(fArr);
  sNum = convert(sArr);
  function convert(arr){
    var num = "";
    if (arr.length>=3) {
      arr.splice(1,1);
    }else if(arr.length==2){
      arr.splice(0,1);
      num = "1";
    }
    arr.forEach(function (item){
      num +=sortArr.indexOf(item);
    });
    return num;
  }
  return parseInt(fNum)>=parseInt(sNum)? fh: sh;
}*/
/*
function wxPromisify(fn,obj={}){
  return new Promise((resolve,reject)=>{
    obj.success = function (res){
      debugger;
      resolve(res);
    }
    obj.fail = function (res){
      reject(res)
    }
    fn(obj);
  })
}*/
/*      wx.login({
        success:function(res){
          if (res.code) {
            //调用登录接口
            let code = res.code;
            wxPromisify(wx.getUserInfo,{
              withCredentials: true,
            })
            .then((res)=>{
              debugger;
              wxPromisify(wx.request,{
                url: 'https://steamclub.wechatapp.vgamer.im/api/wechat/login',
                method:"GET",
                data: {
                  code: code,
                  encrytedData: encodeURIComponent(res.encryptedData),
                  iv: res.iv
                }
              })
            })
            .then((res)=>{
              console.log(res)
            })
            .catch((res)=>{
              console.log(res);
            })

          }else {
            console.log('获取用户登录态失败！' + res.errMsg)
          }
          
        }
      })*/
module.exports = {
  formatTime: formatTime,
  honour: honour
}
